#include "work_manevr.h"
#include "ui_work_manevr.h"

work_manevr::work_manevr(QWidget *parent) :
    QDialog(parent),
    ui(new Ui::work_manevr)
{
    ui->setupUi(this);

    QSqlDatabase db = QSqlDatabase::addDatabase("QSQLITE");
    db.setDatabaseName("smena.db3");
    model_station = new QSqlTableModel(this);
    model_station->setTable("station");
    model_station->select();
    ui->cbStation->setModel(model_station);
    ui->cbStation->setModelColumn(1);
}

void work_manevr::SetActive()
{
    connect(ui->cbStation, SIGNAL(currentIndexChanged(int)), this, SLOT(GetData()));
    connect(ui->teStart,   SIGNAL(dateTimeChanged(QDateTime)), this, SLOT(GetData()));
    connect(ui->teEnd,     SIGNAL(dateTimeChanged(QDateTime)), this, SLOT(GetData()));
    connect(ui->teHot,     SIGNAL(dateTimeChanged(QDateTime)), this, SLOT(GetData()));
}

void work_manevr::GetData()
{
    manevr.station = ui->cbStation->currentIndex();
    manevr.time_start = ui->teStart->dateTime();
    manevr.time_end = ui->teEnd->dateTime();
    manevr.time_hot = ui->teHot->dateTime();
}


void work_manevr::SetData()
{
    ui->cbStation->setCurrentIndex(manevr.station);
    ui->teStart->setDateTime(manevr.time_start);
    ui->teEnd->setDateTime(manevr.time_end);
    ui->teHot->setDateTime(manevr.time_hot);
}

work_manevr::~work_manevr()
{
    delete ui;
}
